package bishi.day39_6_29;

import java.util.Scanner;

/**
 * 最长公共子序列
 * @author 是阿秋啊
 * @date 2022/06/30 15:28
 **/
public class demo2 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()){
            String m = sc.next();
            String n = sc.next();

            System.out.println(LCS(m,n));
        }
    }

    private static int LCS(String m, String n) {
        int mLen = m.length();
        int nLen = n.length();

        int[][] dp = new int[mLen+1][nLen+1];
        for (int i = 1; i <= mLen; i++) {
            for (int j = 1; j <= nLen; j++) {
                if (m.charAt(i - 1) == n.charAt(j - 1)){
                    dp[i][j] = dp[i - 1][j - 1] + 1;
                }else {
                    dp[i][j] = Math.max(dp[i - 1][j],dp[i][j - 1]);
                }
            }
        }
        return dp[mLen][nLen];
    }
}